package com.cloud.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    private final MyInterceptor myInterceptor;

    public InterceptorConfig(MyInterceptor myInterceptor) {
        this.myInterceptor = myInterceptor;
    }

    /**
     * 注册拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册自定义拦截器，指定拦截路径
        registry.addInterceptor(myInterceptor)
                .addPathPatterns("/**")  // 设置需要拦截的请求路径
                .excludePathPatterns("/api/login", "/api/register");  // 排除不需要拦截的路径
    }
}
